package com.bk.ouat.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpSession;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.bk.ouat.common.JsonResponseMaker;
import com.bk.ouat.dto.CategoryDto;
import com.bk.ouat.dto.UserDto;
import com.bk.ouat.service.CategoryService;
import com.bk.ouat.service.UserService;

/**
 * Handles requests for the application home page.
 */
@Controller
public class MainController {
	
	private static final Logger logger = LoggerFactory.getLogger(MainController.class);
	
	private final String USER_SESSION_TAG = "userSession";
	
	@Autowired
	private CategoryService cateService;
	
	
	@RequestMapping(value = "home.do", method = RequestMethod.GET)
	public String home(Model model, HttpSession session) {
		UserDto userSession = (UserDto)session.getAttribute(USER_SESSION_TAG);
		if(userSession == null){
			return "redirect:user/login.do";
		}else{
			return "main";
		}
	}
	
	@RequestMapping(value = "main.do")
	public String main(Model model) {
		
		List<CategoryDto> cateList = cateService.list();
		model.addAttribute("categoryList", cateList);
		model.addAttribute("headerTitle", "전래동화");
		return "main";
	}
	
}
